home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / ezhint.exe / STRINGS.H < prev   
C/C++ Source or Header  |  1992-12-09  |  4KB  |  102 lines

  1. #if defined( Uses_Strings ) && !defined( __Strings )
  2. #define __Strings
  3.  
  4. /********************************************************************/
  5. /*    File:     Strings.h                                               */
  6. /*    Author: Patrick Reilly                                          */
  7. /*    CIS ID:    70274,161                                               */
  8. /*    Description:                                                    */
  9. /*        Strings.h is the header file for using the class Strings.    */
  10. /*    Strings is an easy-to-use class that abstracts string usage in    */
  11. /*    a TV application. This makes program modification (especially    */
  12. /*    in the area of internationalization) easy.                        */
  13. /********************************************************************/
  14.  
  15. #if !defined( __DIR_H )
  16. #include <dir.h>
  17. #endif
  18.  
  19. const ushort    srNull = 0xFFFF;
  20. // srNull defines the End-Of-Structure identifier used by StrRef.
  21. //    Because it identifies the last element in a StrRef structure, you
  22. //    cannot use srNull's value as a string id, or Strings will stop
  23. //    reading the structure when the element is encountered. If you
  24. //    absolutely MUST use the 0xFFFF id for a string, change srNull to
  25. //    a value 0..0xFFFF you are NOT using.
  26.  
  27. /********************************************************************/
  28. /*    Structure:    StrRef                                              */
  29. /*    Description:                                                    */
  30. /*        StrRef is the static structure that Strings uses to ref a    */
  31. /*    a string - it includes the string id, and an asciiz string which*/
  32. /*    holds the string value. When creating a static array of StrRef    */
  33. /*    for use with Strings, the last entry in the array MUST have        */
  34. /*    srNull (defined above) as the id value.                            */
  35. /********************************************************************/
  36.  
  37. struct StrRef
  38.     {
  39.     ushort id;
  40.     char *str;
  41.     };
  42.  
  43. /********************************************************************/
  44. /*    Class:    Strings                                                    */
  45. /*    Description:                                                    */
  46. /*        Strings is a string-reference class that allows abstraction    */
  47. /*    of string usage in a TV application. Use Strings to access char    */
  48. /*    display data (max string lengh = 256 for string resource files)    */
  49. /*    so that the actual char strings are isolated to one location    */
  50. /*    (either an array of StrRef or a string resource file). There are*/
  51. /*     two sources of data for Strings: either a StrRef array, or a    */
  52. /*    string resource file. For either source, multiple instances of    */
  53. /*    Strings can use the same source. For a StrRef array source,        */
  54. /*    Strings does not "own" the array; so if the array is dynamically*/
  55. /*    allocated, it is up to the calling function to discard the array*/
  56. /*    when it is no longer needed.                                    */
  57. /********************************************************************/
  58.  
  59. class far TStringList;
  60. class far ifpstream;
  61.  
  62. class Strings
  63.     {
  64.     public:
  65.  
  66.         Strings();                        // create an empty Strings.
  67.         Strings( Strings& s );            // copy ctor.
  68.         ~Strings();                        // clean up.
  69.  
  70.         char *operator[] ( ushort id );    // return pointer to string
  71.         char *get( ushort id );            // referenced by id.
  72.  
  73.         void clear();                    // clear Strings, make it empty.
  74.         Boolean load( StrRef *arg );    // load from a StrRef array.
  75.         Boolean load( char *fspec );    // load from the string resource
  76.                                         // whose name is fspec.
  77.         Boolean store( char *fspec );    // create a string resource file with
  78.                                         // the name fspec and write contents
  79.                                         // to it. NOTE: can only be used if
  80.                                         // load(StrRef *) was called to make
  81.                                         // Strings.
  82.  
  83.     protected:
  84.  
  85.         StrRef **items;                    // array of pointers to StrRef items.
  86.                                         // Sorted by id.
  87.         int count;                      // Number of entries in items.
  88.         Boolean search( ushort id, int& pos );
  89.                                         // used by load(StrRef *) and get()
  90.                                         // to find an id's position in items.
  91.  
  92.         ifpstream *is;                    // pointer to string resource file.
  93.         TStringList *slist;                // TStringList for srf.
  94.         char buf[256];                    // internal buffer for get()
  95.         char fname[MAXPATH];            // srf file name (for copy ctor).
  96.     };
  97.  
  98. inline char *Strings::operator[] ( ushort id )
  99.     {    return get(id);    }
  100.  
  101. #endif    // __Strings
  102.